//
//  MKUITabBarContentViewContainer.m
//  MKUI
//
//  Created by sushangjin on 16/3/29.
//  Copyright © 2016年 sushangjin. All rights reserved.
//

#import "MKUITabBarContentContainer.h"

@implementation MKUITabBarContentContainer
- (NSArray<UITabBarItem *> *)tabBarItems{
	NSArray<UITabBarItem *> *list = (NSArray<UITabBarItem *> *)[self.contents valueForKeyPath:@"tabBarItem"];
	return list;
}
- (void)setSelectedContent:(id<MKUITabBarContentProtocol>)selectedTabBarContentView{
    NSInteger index = [self.contents indexOfObject:selectedTabBarContentView];
    self.selectedIndex = index;
}
- (id<MKUITabBarContentProtocol>)selectedContent{
    id<MKUITabBarContentProtocol> view = nil;
    NSInteger index = self.selectedIndex;
    if(index>=0&&index<self.contents.count){
        view = self.contents[index];
    }
    return view;
}
- (void)setSelectedIndex:(NSInteger)index{
    if(index>=0&&index<self.contents.count){
        _selectedIndex = index;
    }
}

- (void)reloadData{
    [self reloadDataWithAnimated:NO];
}
- (void)reloadDataWithAnimated:(BOOL)animated{
    
}
- (void)setSelectedIndex:(NSInteger)index animated:(BOOL)animated{
    self.selectedIndex = index;
    [self reloadDataWithAnimated:animated];
}
- (BOOL)canScrollContentView{
    return NO;
}
- (CGSize)sizeThatFits:(CGSize)size{
    UIView *v = self.selectedContent.tabBarContentView;
    CGSize sizeFits = v?[v sizeThatFits:size]:[super sizeThatFits:size];
    return sizeFits;
}
- (CGSize)intrinsicContentSize{
    UIView *v = self.selectedContent.tabBarContentView;
    CGSize size = v?[v intrinsicContentSize]:[super intrinsicContentSize];
    return size;
}
@end
